﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Windows.Forms
{
    public class FormEdicao : Form
    {
        int idItem;
        public FormEdicao()
            : this(0)
        {
        }
        public FormEdicao(int idItem)
            : base()
        {
            this.idItem = idItem;
            
        }
        public int IdItem
        {
            get { return idItem; }
            set { idItem = value; }
        }
        public void SetarIDDado(int id)
        {
            this.idItem = id;            
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // FormEdicao
            // 
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormEdicao";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.ResumeLayout(false);

        }
    }
    public static class helper
    {
        public static void ExbirFormulario(this FormEdicao destino, Form origem )
        {
            destino.WindowState = FormWindowState.Maximized;
            destino.StartPosition = FormStartPosition.CenterParent;

            if (origem.MdiParent != null)
            {
                var formulario = (from f in origem.MdiParent.MdiChildren
                                  where f.Name == destino.Name
                                  select f).FirstOrDefault();

                if (formulario != null)
                {
                    formulario.Activate();
                }
                else
                {
                    destino.MdiParent = origem.MdiParent;
                    destino.Show();
                }
            }
            else
            {
                destino.MdiParent = origem;
                destino.Show();
            }

        }
    }
}
